package cn.stronglink.asset.module.patrol.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.plugins.Page;
import cn.stronglink.asset.module.patrol.service.PatrolPlanService;
import cn.stronglink.asset.module.patrol.vo.PatrolPlanSearchVo;
import cn.stronglink.asset.module.patrol.vo.PatrolPlanVo;
import cn.stronglink.suite.core.base.AbstractController;
import cn.stronglink.suite.core.log.annotation.OperateLog;
import cn.stronglink.suite.core.log.annotation.OperateLog.OpType;

@Controller
@RequestMapping(value="patrolPlan")
public class PatrolPlanController extends AbstractController{
	@Autowired
	private PatrolPlanService patrolPlanService;
	
	
	/**
	 * 添加巡检计划
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param patrolPlanVo
	 * @return
	 */
	@OperateLog(module = "巡检计划管理",desc="创建巡检计划", type = OpType.ADD)
	@RequestMapping(value="addPatrolPlan")
	public ResponseEntity<ModelMap> addPatrolPlan(ModelMap modelMap,HttpServletRequest request,
			HttpServletResponse response,@RequestBody PatrolPlanVo patrolPlanVo) {
		patrolPlanService.addPatrolPlan(patrolPlanVo);
		return setSuccessModelMap(modelMap,null);
	}
	
	
	@RequestMapping(value="qryById")
	public ResponseEntity<ModelMap> qryById(ModelMap modelMap,HttpServletRequest request,
			HttpServletResponse response,@RequestBody Long id) {
		PatrolPlanVo paln=patrolPlanService.qryById(id);
		return setSuccessModelMap(modelMap,paln);
	}
	
	/**
	 * 更新巡检计划
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param patrolPlanVo
	 * @return
	 */
	@OperateLog(module = "巡检计划管理",desc="修改巡检计划", type = OpType.UPDATE)
	@RequestMapping(value="updatePatrolPlan")
	public ResponseEntity<ModelMap> updatePatrolPlan(ModelMap modelMap,HttpServletRequest request,
			HttpServletResponse response,@RequestBody PatrolPlanVo patrolPlanVo){
		patrolPlanService.updatePatrolPlan(patrolPlanVo);
		return setSuccessModelMap(modelMap,null);
	}
	
	/**
	 * 删除巡检计划
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param patrolPlanIds
	 * @return
	 */
	@OperateLog(module = "巡检计划管理",desc="删除巡检计划", type = OpType.DEL)
	@RequestMapping(value="deletePatrolPlan")
	public ResponseEntity<ModelMap> deletePatrolPlan(ModelMap modelMap,HttpServletRequest request,
			HttpServletResponse response,@RequestBody Long id){
		patrolPlanService.delPatrolPlanById(id);
		return setSuccessModelMap(modelMap,null);
	}
	
	/**
	 * 查询巡检计划
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param queryParams
	 * @return
	 */
	@RequestMapping(value="queryList")
	public ResponseEntity<ModelMap> queryPatrolPlanList(ModelMap modelMap,HttpServletRequest request,
			HttpServletResponse response,@RequestBody Map<String,Object> params){
		@SuppressWarnings("unchecked")
		Page<PatrolPlanSearchVo> page = (Page<PatrolPlanSearchVo>) super.getPage(params);
		Page<PatrolPlanSearchVo> data = patrolPlanService.queryPatrolPlanList(page, params);
		return setSuccessModelMap(modelMap,data);
	}
	

	
}
